# Unittests
from django.test import TestCase
from bliki.models import Article

class ArticleTest(TestCase):
    fixtures = ['test_article',]

    def setUp(self):
        self.first_post = Article.objects.get(pk=1)
        self.second_post = Article.objects.get(pk=2)

    def testArticleBlog(self):
        self.assertTrue(self.first_post.blog_post)
        self.assertTrue(self.second_post.blog_post)
        self.assertFalse(self.first_post.latest)
        self.assertTrue(self.second_post.latest)

    def testArticleCounts(self):
        self.assertEquals(Article.blog_post_objects.all().count(), 1)
        self.assertEquals(Article.objects.all().count(), 2)

    def testArticleSaves(self):
        article = Article(name="MyWikiPage", body='Body counts')
        article.save()
        first_id = article.id
        self.assertTrue(article.latest)
        self.assertFalse(article.blog_post)
        next_article = Article(name="MyWikiPage", body='Body counts - reloaded')
        next_article.save()
        # Latest
        article = Article.objects.get(pk=first_id)
        self.assertFalse(article.latest)
        self.assertTrue(next_article.latest)

